package com.naodong.shenluntiku.mvp.view.adapter;

import android.text.Html;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.naodong.shenluntiku.R;
import com.naodong.shenluntiku.mvp.model.bean.SubjectInfo;
import com.naodong.shenluntiku.mvp.model.bean.SubjectOption;

import me.shingohu.man.util.UiUtils;

/**
 * Created by hujie on 17/5/22.
 */

public class SubjectHistoryListAdapter extends BaseQuickAdapter<SubjectInfo, BaseViewHolder> {


    /**
     * Same as QuickAdapter#QuickAdapter(Context,int) but with
     * some initialization data.
     */
    public SubjectHistoryListAdapter() {
        super(R.layout.swipe_item_subject);

    }


    @Override
    protected void convert(BaseViewHolder helper, SubjectInfo item) {


        SubjectInfo subjectInfo = item;

        helper.setText(R.id.questionTV, Html.fromHtml(subjectInfo.getSubCon()));

        LinearLayout optionContainerView = helper.getView(R.id.optionContainer);
        optionContainerView.removeAllViews();

        for (SubjectOption option : subjectInfo.getSubOptions()) {
            View optionView = mLayoutInflater.inflate(R.layout.collect_subject_item_option, null);
            TextView optionIndexTV = (TextView) optionView.findViewById(R.id.optionIndexTV);
            TextView optionTV = (TextView) optionView.findViewById(R.id.optionTV);
            optionIndexTV.setText(option.getOpName());
            optionTV.setText(option.getOpCon());
            optionContainerView.addView(optionView);

            if (option.getOpIsCorrect() == 1) {
                optionTV.setTextColor(UiUtils.getColor(R.color.color72CEB7));
                optionIndexTV.setText("");
                optionIndexTV.setBackgroundResource(R.drawable.ico_circle_right);
            } else {
                if (subjectInfo.getuChooseIds().contains(option.getOpId())) {
                    optionIndexTV.setTextColor(UiUtils.getColor(R.color.colorAccent));
                    optionIndexTV.setBackgroundResource(R.drawable.ico_circle_error);
                    optionIndexTV.setText("");
                }
            }


        }


    }
}
